package com.ksp.wke.kspt01;
import static com.ksp.com.KSPCOM_BasConst.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ksp.api.KSPAPI_UsrAuth;
import com.ksp.dom.KSPDOM_ResDta;
import com.ksp.dom.KSPDOM_User;

import net.minidev.json.JSONArray;

/**
 * 用户任务列表查询
 * @author anye
 *
 */
@Controller
public class KSPT01Controller {

	
	private static final String SQL_TSK_QRY = "";
	
	private static final String SQL_KSP_UPD = "";
	
	private static final String SQL_KSP_T01 = "";
	
	@Autowired
	private KSPT01Mapper kspt01Mapper;

	@RequestMapping("/tsk/KSPT01")
	@ResponseBody
	public KSPDOM_ResDta iniPam(ServletRequest request) {
		String wKspTtl = request.getParameter(KSP_TTL);
		String wKspCon = request.getParameter(KSP_CON);
		String wImpDeg = request.getParameter(IMP_DEG);
		String wDeaUsr = request.getParameter(DEA_USR);
		String wDesUnm = request.getParameter(DEA_UNM);
		String wTskTyp = request.getParameter(TSK_TYP);
		
		KSPDOM_User usrInf = KSPAPI_UsrAuth.getUsrInf(request);
		
		Map<String, Object> wPamMap = new HashMap<>();
		wPamMap.put(KSP_TTL, wKspTtl);
		wPamMap.put(KSP_CON, wKspCon);
		wPamMap.put(IMP_DEG, wImpDeg);
		wPamMap.put(DEA_USR, wDeaUsr);
		wPamMap.put(DEA_UNM, wDesUnm);
		wPamMap.put(TSK_TYP, wTskTyp);
		wPamMap.put(QUA_USR, usrInf.getUsroam());
		wPamMap.put(QUA_UNM, usrInf.getUsrnam());
		
		KSPDOM_ResDta wResDta = new KSPDOM_ResDta();
		try {
			wResDta = exeSrv(wPamMap);
		} catch (Exception e) {
			wResDta.setCod("400");
			wResDta.setMsg(e.getMessage());
		}
		return wResDta;
	}

	public KSPDOM_ResDta exeSrv(Map<String, Object> pPamMap) {
		Map<String, Object> wTchPamMap = new HashMap<>();
		List<Map<String, Object>> wTchLst = kspt01Mapper.qryMaxTch(wTchPamMap);
		int wInsTch = ORG_TCH;
		/*
		 * isEmpty() 分配了内存空间，值为空，是绝对的空，是一种有值（值 = 空）  
    	 "" 分配了内存空间，值为空字符串，是相对的空，是一种有值（值 = 空字串）  
    	null  是未分配内存空间，无值，是一种无值(值不存在)
		 * */
		try {
			if ((wTchLst != null) && (wTchLst.size() > 0) && (wTchLst.get(0) != null)) {
				String wCurTch = wTchLst.get(0).get("TCH_IDN").toString();
				if (wCurTch != null && !wCurTch.isEmpty()) {
					wInsTch = Integer.parseInt(wCurTch) + 1;
				}
				Integer.parseInt(wCurTch);
			} 
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		pPamMap.put(TCH_IDN, wInsTch);
		
		int wResCnt = kspt01Mapper.insKspTsk(pPamMap);
		if (wResCnt > 0) {
			return KSPDOM_ResDta.buildSucc("");
		} else {
			return KSPDOM_ResDta.buildFail("新增问题失败");
		}

	}
}
